﻿/*----------------------------------------------------------------
//  <copyright file="OrganizationClaimBase.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2023-12-06 18:28</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Identity.Entities
{
    #region "组织机构声明信息基类"
    /// <summary>
    /// 组织机构声明信息基类
    /// </summary>
    /// <typeparam name="TKey">组织机构声明编号类型</typeparam>
    /// <typeparam name="TOrganizationKey">组织机构编号类型</typeparam>
    public abstract class OrganizationClaimBase<TKey, TOrganizationKey> : EntityBase<TKey>, ICreatedTime
        where TKey : struct, IEquatable<TKey>
        where TOrganizationKey : struct, IEquatable<TOrganizationKey>
    {
        #region "属性"
        #region "获取或设置 组织机构编号"
        /// <summary>
        /// 获取或设置 组织机构编号
        /// </summary>
        [Column("OrganizationId")]
        [Required]
        [DisplayName("组织机构编号")]
        public TOrganizationKey OrganizationId { get; set; }
        #endregion

        #region "获取或设置 声明类型"
        private string _ClaimType = "";
        /// <summary>
        /// 获取或设置 声明类型
        /// </summary>
        [Column("ClaimType")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("声明类型")]
        public string ClaimType { get { return _ClaimType; } set { _ClaimType = value.ReplaceNull(); } }
        #endregion
        #region "获取或设置 声明值"
        private string _ClaimValue = "";
        /// <summary>
        /// 获取或设置 声明值
        /// </summary>
        [Column("ClaimValue")]
        [StringSize(StringSizeType.General)]
        [DisplayName("声明值")]
        public string ClaimValue { get { return _ClaimValue; } set { _ClaimValue = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 创建时间 ICreatedTime、ICreationAudited  可装载接口，在数据创建时可自动设置当前时间"
        /// <summary>
        /// 获取或设置 创建时间
        /// </summary>
        [Column("CreatedTime")]
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }
        #endregion

        #endregion

        #region "方法"
        #region "使用类型和值创建一个声明对象"
        /// <summary>
        /// 使用类型和值创建一个声明对象
        /// </summary>
        /// <returns></returns>
        public virtual Claim ToClaim()
        {
            return new Claim(ClaimType, ClaimValue);
        }
        #endregion
        #region "使用一个声明对象初始化"
        /// <summary>
        /// 使用一个声明对象初始化
        /// </summary>
        /// <param name="other">声明对象</param>
        public virtual void InitializeFromClaim(Claim other)
        {
            ClaimType = other?.Type;
            ClaimValue = other?.Value;
        }
        #endregion

        #endregion

    }
    #endregion

}
